#include "cherryusb_app.h"

#include "usbd_core.h"
#include "usbd_cdc.h"
#include "usb_hid.h"

#include "cmsis_os2.h"

#include "shell.h"
#include "logs.h"

#define USB_USE_CLASS_CDC        (0)
#define USB_USE_CLASS_HID        (1)


void cherryusb_cdc_send_test(void)
{
#if USB_USE_CLASS_CDC
    extern void cdc_acm_data_send_with_dtr_test(uint8_t busid);
    extern void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr);

    usbd_cdc_acm_set_dtr(0, 0, true);
    cdc_acm_data_send_with_dtr_test(0);
    usbd_cdc_acm_set_dtr(0, 0, false);
#endif
}
#if USB_USE_CLASS_CDC
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), cdc_s_test, cherryusb_cdc_send_test, cdc send test);
#endif

#if USB_USE_CLASS_HID
void cherryusb_hid_send_test(void)
{
    extern void hid_keyboard_send(uint8_t busid, uint8_t *data, uint32_t len);

    uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00};
    hid_keyboard_send(0, sendbuffer, 8);
    sendbuffer[2] = 0x00;
    hid_keyboard_send(0, sendbuffer, 8);
}
SHELL_EXPORT_CMD(SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC), hid_s_test, cherryusb_hid_send_test, hid send test);
#endif

void cherryusb_app_init(void)
{
#if USB_USE_CLASS_CDC
    extern void cdc_acm_init(uint8_t busid, uintptr_t reg_base);
    cdc_acm_init(0, USB_OTG_FS_BASE);
#endif

#if USB_USE_CLASS_HID
    extern void hid_keyboard_init(uint8_t busid, uintptr_t reg_base);
    hid_keyboard_init(0, USB_OTG_FS_BASE);
#endif
}
